/*
 * main.c -- this file is part of mISPL.
 * Copyright (C) 2011 Christian Krause
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */
#include "config.h"
#include "common.h"
#include "node.h"
#include "program.h"

int main(int argc, char** argv) {
    
	// Initialize random number generator:
	srand(time(NULL));

    printf("This if m-ispl %s\n", VERSION);

    program_t program = program_init(6, 2, 2, 2);
    program_t backup  = program_copy(program);
    block_t history = 	block_init(program->regcount, 128);

    int i;
    for (i=0; i<1000; ++i) {

    	program->regcount = backup->regcount;
    	program->startlength = backup->startlength;
    	program->looplength = backup->looplength;
    	program->endlength = backup->endlength;

    	program_fill_rand(program);
//        program_print(program);
//        printf("\nSimplified:\n");
        program_simplify(program);
        program_print(program);
        printf("\n");
        sequence_t result = program_exec(program, history, 1024);
        if (result!=NULL) {
        	sequence_print(result);
        	sequence_clear(result);
        }
        printf("\n");

    }
    block_clear(history);
    program_clear(program);
    program_clear(backup);
    return 0;

}
